package com.waiting.leetcode;

/**
 * @Description
 * @Author bjweitingting
 * @Date 2019/3/5
 **/
public class PalindromicSubstrings647 {
    public static void main(String[] args) {
        PalindromicSubstrings647 test = new PalindromicSubstrings647();
        System.out.println(test.countSubstrings("aaa"));
    }

    public int countSubstrings(String s) {
        if (s == null) {
            return 0;
        }
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum += extend(s, i, i);
            sum += extend(s, i, i + 1);
        }
        return sum;
    }

    public int extend(String s, int l, int h) {
        int i = l, j = h;
        while (l >= 0 && h < s.length() && s.charAt(l) == s.charAt(h)) {
            l--;
            h++;
        }
        return i - (l + 1) + 1;
    }
}
